<template>
  <div class="box">
    <el-tabs style="height: 80px" v-model="activeName" @tab-click="handleClick">
      <el-tab-pane></el-tab-pane>
      <el-tab-pane label="当前考试" name="new"></el-tab-pane>
      <el-tab-pane label="历史考试" name="histiy"></el-tab-pane>
    </el-tabs>
    <div class="innerBox">

      <div v-for="item in tableList" class="item">
        <div class="picture">
          <el-image :src="item.coverPicture" fit="cover" style="width: 100%;height: 100%"></el-image>
        </div>
        <div class="bottom">
          <div>{{ item.examinationName }}</div>
          <div>开始时间：{{ item.testStartTime }}</div>
          <div>结束时间：{{ item.testEndTime }}</div>
          <div>考试时长：{{ item.answerTime }}</div>
          <template v-if="item.examinationAndUserList">

            <div v-if="item.examinationAndUserList[0].reserve1==0">参与情况：未参与</div>
            <div v-else>答题次数：{{ item.examinationAndUserList[0].reserve2 }}</div>

            <div>
              <el-button size="mini" type="primary" @click="goKaoShi(item)">参加</el-button>
            </div>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {getExamHallHistoryList, getExamHallList} from "@/api/examination";

export default {
  data() {
    return {
      tableList: [],
      activeName: 'new'
    }
  },
  mounted() {
    this.handleClick()
  },
  methods: {
    //判断当前考试的情况
    getSituation(val) {
      if (val.examinationAndUserList) {
        if (val.examinationAndUserList[0].reserve1 == 0) {
          return '未参加'
        }
      }
    },
    //参加考试
    goKaoShi(val) {
      let detail=JSON.parse(JSON.stringify(val))

      detail['id']=val.examinationPaperSummaryId
      detail['examinationId']=val.examinationId
      detail['userAndId']=val.examinationAndUserList[0].examinationAndUserId

      localStorage.setItem('examHallData', JSON.stringify(detail));
      this.$router.push({path: '/examination/onlineExams'})
    },
    handleClick(val, a, b) {
      if (this.activeName == 'new') {
        getExamHallList().then(res => {
          if (res.code == 200) {
            this.tableList = res.rows
          }
        })
      } else {
        getExamHallHistoryList().then(res => {
          if (res.code == 200) {
            this.tableList = res.rows
          }
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.box {
  height: 100%;
  overflow: auto;
  background-color: #f1f3f8;

  .innerBox {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding: 15px 15px 15px 0;
  }
}

.item {
  width: 233px;
  height: 300px;
  background-color: white;
  border-radius: 10px;
  margin-left: 15px;
  overflow: hidden;
  transition: 0.5s;
  margin-bottom: 15px;

  .picture {
    height: 140px;
    border-radius: 10px;
    overflow: hidden;
  }

  > .bottom {
    height: calc(100% - 140px);
    padding-left: 15px;

    > div:nth-of-type(1) {
      line-height: 30px;
      font-size: 16px;
      margin-top: 8px;
    }

    > div:nth-of-type(2) {
      line-height: 20px;
      font-size: 12px;
      color: #999;
    }

    > div:nth-of-type(3) {
      line-height: 20px;
      font-size: 12px;
      color: #999;
    }

    > div:nth-of-type(4) {
      line-height: 20px;
      font-size: 12px;
      color: #999;
    }

    > div:nth-of-type(5) {
      line-height: 20px;
      font-size: 12px;
      color: #999;
    }

    > div:nth-of-type(6) {
      padding-top: 10px;
      display: flex;
      justify-content: flex-end;
      padding-right: 15px;
    }
  }

}

.item:hover {
  box-shadow: 0 0 10px #ccc;
  transform: translateY(-5px);
}

.el-tabs {
  ::v-deep .el-tabs__item {
    font-size: 30px;
    height: 60px;
    line-height: 60px;
  }

}
</style>
